package com.ebeijia.web.controller;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ebeijia.common.CommonCodeDefine;
import com.ebeijia.mybatis.pojo.CommonUserInfo;
import com.ebeijia.mybatis.pojo.UserInfo;
import com.ebeijia.service.user.CommonUserService;
import com.ebeijia.util.LoggerUtil;
import com.ebeijia.web.ResponseMessage;

@Controller
@RequestMapping("/common")
public class CommonController {

	@Autowired
	private CommonUserService commonUserService;
	/***
	 * 两表联查  根据用户Id查询
	 * @param userId
	 * @param request
	 * @return
	 */
	@RequestMapping("/getUserId")
	@ResponseBody
	public ResponseMessage getUserIdByHomeSource(String userId,HttpServletRequest request) {
		userId = request.getParameter("userId");
		List<Map<String, CommonUserInfo>> comm = commonUserService
				.getUserIdByHomeSource(userId);

		if (comm != null) {
			for (Map<String, CommonUserInfo> map : comm) {
				SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
				// getUserinfo().setUnixByDate(date.format(commonUserInfo.getUserinfo().getBindDate()));
				// .getUserinfo().setLastMoeny("21.43");
			}

			return ResponseMessage.success(comm);
		}
		return ResponseMessage.error("0005", "用戶不存在");
	}
	/**
	 * 根据房源编号 
	 * @param userNo
	 * @return
	 */
	@RequestMapping("/getUserNo")
	@ResponseBody
	public ResponseMessage getUserNOHome(String userNo) {

		CommonUserInfo com = commonUserService.getUserNOHome(userNo);

		return ResponseMessage.success(com);
	}
	
	/**
	*  
	 * @param userNo
	 * @return
	 *//*
	@RequestMapping("/getOpenId")
	@ResponseBody
	public ResponseMessage getOpenId(String openId,HttpServletRequest request) {
		openId = request.getParameter("openId");
		List<CommonUserInfo> in = commonUserService.getOpenId(openId);
		if (in != null) {
			SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
			in.setUnixByDate(date.format(in.getBindDate()));
			in.setLastMoeny("21.43");
			return ResponseMessage.success(in);
		} else {
			return ResponseMessage.error(
					CommonCodeDefine.ERROR_NO_BIND.getCode(),
					CommonCodeDefine.ERROR_NO_BIND.getDesc());
		}

		
	}*/

}
